package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

/**
 * 上架专辑
 * @param albumId
 * @return
 */
    @Operation(summary = "上架专辑")
    @GetMapping("/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        this.searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * 下架专辑
     * @param albumId
     * @return
     */
    @Operation(summary = "下架专辑")
    @GetMapping("lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        this.searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    @Operation(summary ="批量上传")
    @GetMapping("/bathUpperAlbum")
    public Result bathUpperAlbum(){
        for (long i = 1; i <=1600 ; i++) {
            searchService.upperAlbum(i);
        }
        return Result.ok();
    }

    /**
     * 根据条件检索Es
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "根据条件检索Es")
    @PostMapping
    public Result searchAlbum(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo searchResponseVo=searchService.searchAlbum(albumIndexQuery);
        return Result.ok(searchResponseVo);
    }
    @Operation(summary = "自动补全")
    @GetMapping("/completeSuggest/{keyword}")
    public Result completeSuggest(@PathVariable String keyword){
        List<String> suggestString=searchService.completeSuggest(keyword);
        return Result.ok(suggestString);
    }

    /**
     * 更新排行榜
     * @return
     */
    @Operation(summary = "更新排行榜")
    @GetMapping("updateLatelyAlbumRanking")
    public Result updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }

    /**
     * 获取排行榜列表
     * @param trackId
     * @param dimension
     * @return
     */
    @Operation(summary = "获取排行榜列表")
    @GetMapping("/findRankingList/{trackId}/{dimension}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long trackId,@PathVariable String dimension){
        List<AlbumInfoIndexVo> albumInfoIndexVoList = searchService.findRankingList(trackId,dimension);
        return Result.ok(albumInfoIndexVoList);
    }
}

